// JavaScript Document
var isIE=!!document.all;

if(document.getElementById('yNav')){
	var g=function(id){return document.getElementById(id);};
	var c=function(tag){return document.createElement(tag);};
	var yNav=function(){this.init();};
	yNav.prototype={
		init:function(){
			this.container=g("yNav");
			$("#yNav div.bk").each(function(index, ele){
				$(':first-child', this).mouseover(function(event){
					if($(this).attr('tagName') == 'DIV'){
						$(this).addClass('hover');
						$(this).scrollLeft(100);
						var x=(event.offsetX)?event.offsetX:event.layerX;
						var scrollW=this.scrollWidth;
						this.scrollLeft=scrollW*x/this.parentNode.clientWidth-this.parentNode.clientWidth+20;
					}
				});
				$(':first-child', this).mouseout(function(){
					if($(this).attr('tagName') == 'DIV'){
						$(this).removeClass('hover');
					}
				});
			});
			titleAttr(this.container.getElementsByTagName("a"));
		}
	};
	function getElementTop(element){
		var actualTop=element.offsetTop;
		var current1=element.offsetParent;
		while(current1!==null){
			actualTop+=current1.offsetTop;
			current1=current1.offsetParent;
		}
		return actualTop;
	}
	
	var titleBox=g("title-box"),titleY=getElementTop(g("yNav"));
	function showTitle(str,x,y,color){
		if(titleBox){
			titleBox.style.display="block";
		}else{titleBox=c("div");
			titleBox.id="title-box";
			titleBox.style.top=titleY+"px";
			var pointer=c("span");
			pointer.innerHTML="&diams;";
			titleBox.appendChild(pointer);
			document.body.appendChild(titleBox);
		}
		titleBox.innerHTML="<span>&diams;</span>"+str;
		titleBox.style.left=(x-titleBox.offsetWidth/2)+"px";
		if(color){
			titleBox.style.backgroundColor=color;
			titleBox.firstChild.style.color=color;
		}
	}
	//titleAttr
	var t=null;
	function titleAttr(elems){
		for(var i=0;i<elems.length;i++){
			if(elems[i].getAttribute("tit")){
				elems[i].onmouseover=function(e){
					var str=this.getAttribute("tit");
					if(t)clearTimeout(t);
					e=e||event;
					var x=e.clientX,y=e.clientY;
					var color=renderCss(this,"backgroundColor");
					t=setTimeout(function(){showTitle(str,x,y,color);
					},10);};
					elems[i].onmouseout=function(){if(t)clearTimeout(t);
					t=setTimeout(function(){if(titleBox)titleBox.style.display="none";},10);};
			}
		}
	}
	//renderCss
	function renderCss(elem,css){
		if(isIE){
			if(elem.currentStyle) return elem.currentStyle[css]; else return"";
		}else{
			return document.defaultView.getComputedStyle(elem,false)[css]||"";
		}
	}
	//实例化
	var nav=new yNav();
}